package com.nitty.cash.loop.ui.dialog

import android.content.Context
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
import android.view.WindowManager
import com.nitty.cash.loop.NittyApp
import com.nitty.cash.loop.R
import com.nitty.cash.loop.common.CommonDialog
import com.nitty.cash.loop.databinding.DialogGuideTabBinding

/**
 * NittyCash
 * @Author wwdeng
 * @CreateTime: 2024/11/13 15:41
 * @Annotation：Tab切换引导dialog
 */
class NittyGuideTabDialog: CommonDialog {

    private lateinit var binding: DialogGuideTabBinding
    private var mCallback: IDialogCallback? = null
    private var showGuideIndex = 1
    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    override fun initWindow() {
        val params = window!!.attributes
        params.width = WindowManager.LayoutParams.MATCH_PARENT
        params.height = NittyApp.app.getPhoneHeight()
        window!!.attributes = params
        window!!.setWindowAnimations(R.style.dialog_slide_anim) //修改动画样式
        window!!.setGravity(Gravity.BOTTOM)
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun getRootView(): View {
        binding = DialogGuideTabBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initView() {
        showGuideIndex = 1
        showNittyTabGuideIndex()
    }

    override fun initListener() {
        setOnClickListener(binding.tabGuideLayout) //关闭
    }

    override fun loadData() {
    }

    override fun onViewClick(v: View?) {
        if (showGuideIndex == 2){
            dismiss()
            return
        }
        if (showGuideIndex == 1){
            showGuideIndex = 2
            showNittyTabGuideIndex()
        }
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    private fun showNittyTabGuideIndex(){
        when(showGuideIndex){
            1 -> {
                binding.guideApplyLayout.visibility = View.VISIBLE
                binding.applyItemLayout.visibility = View.VISIBLE

                binding.guideRepayLayout.visibility = View.GONE
                binding.repayItemLayout.visibility = View.INVISIBLE
            }
            2 -> {
                binding.guideApplyLayout.visibility = View.GONE
                binding.applyItemLayout.visibility = View.INVISIBLE

                binding.guideRepayLayout.visibility = View.VISIBLE
                binding.repayItemLayout.visibility = View.VISIBLE
            }
        }
    }

}